home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / bash / bash-108 / bash-108.zoo / src / jobs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-12  |  6.7 KB  |  230 lines

  1. /* jobs.h -- structures and stuff used by the jobs.c file. */
  2.  
  3. #include "quit.h"
  4.  
  5. /* Cadmus machines are brain-dead from the moment of fission, like all
  6.    bacteria. */
  7. #if defined (cadmus) || defined (BrainDeath)
  8. #undef HAVE_WAIT_H
  9. #endif /* BrainDeath */
  10.  
  11. /* HP/UX 6.x sys/wait.h is a complete loss when it comes to the WIF macros.
  12.    Pretend we don't have a wait.h. */
  13. #if defined (hpux) && !defined (_POSIX_VERSION)
  14. #undef HAVE_WAIT_H
  15. #endif
  16.  
  17. #if defined (HAVE_WAIT_H)
  18. #include <sys/wait.h>
  19. #else
  20.  
  21. #include "endian.h"
  22.  
  23. #if !defined (_POSIX_VERSION)
  24. #if defined (LITTLE_ENDIAN)
  25. union wait
  26.   {
  27.     int    w_status;        /* used in syscall */
  28.  
  29.     /* Terminated process status. */
  30.     struct
  31.       {
  32.     unsigned short
  33.       w_Termsig  : 7,    /* termination signal */
  34.       w_Coredump : 1,    /* core dump indicator */
  35.       w_Retcode  : 8,    /* exit code if w_termsig==0 */
  36.       w_Fill1    : 16;    /* high 16 bits unused */
  37.       } w_T;
  38.  
  39.     /* Stopped process status.  Returned
  40.        only for traced children unless requested
  41.        with the WUNTRACED option bit. */
  42.     struct
  43.       {
  44.     unsigned short
  45.       w_Stopval : 8,    /* == W_STOPPED if stopped */
  46.       w_Stopsig : 8,    /* actually zero on XENIX */
  47.       w_Fill2   : 16;    /* high 16 bits unused */
  48.       } w_S;
  49.   };
  50.  
  51. #else  /* if !LITTLE_ENDIAN */
  52.  
  53. /* This is for big-endian machines like the IBM RT, HP 9000, or Sun-3 */
  54.  
  55. union wait
  56.   {
  57.     int    w_status;        /* used in syscall */
  58.  
  59.     /* Terminated process status. */
  60.     struct
  61.       {
  62.     unsigned short w_Fill1    : 16;    /* high 16 bits unused */
  63.     unsigned       w_Retcode  : 8;    /* exit code if w_termsig==0 */
  64.     unsigned       w_Coredump : 1;    /* core dump indicator */
  65.     unsigned       w_Termsig  : 7;    /* termination signal */
  66.       } w_T;
  67.  
  68.     /* Stopped process status.  Returned
  69.        only for traced children unless requested
  70.        with the WUNTRACED option bit. */
  71.     struct
  72.       {
  73.     unsigned short w_Fill2   : 16;    /* high 16 bits unused */
  74.     unsigned       w_Stopsig : 8;    /* signal that stopped us */
  75.     unsigned       w_Stopval : 8;    /* == W_STOPPED if stopped */
  76.       } w_S;
  77.   };
  78.  
  79. #endif /* LITTLE_ENDIAN */
  80.  
  81. #define    w_termsig w_T.w_Termsig
  82. #define w_coredump w_T.w_Coredump
  83. #define w_retcode w_T.w_Retcode
  84. #define w_stopval w_S.w_Stopval
  85. #define w_stopsig w_S.w_Stopsig
  86.  
  87. /* Note that sys/wait.h defines these for Posix systems. */
  88. #define    WSTOPPED 0177
  89. #define WIFSTOPPED(x) (((x) . w_stopval) == WSTOPPED)
  90. #define WIFEXITED(x) ((! (WIFSTOPPED (x))) && (((x) . w_termsig) == 0))
  91. #define WIFSIGNALED(x) ((! (WIFSTOPPED (x))) && (((x) . w_termsig) != 0))
  92.  
  93. #endif /* _POSIX_VERSION */
  94. #endif  /* !HAVE_WAIT_H */
  95.  
  96. #if !defined (_POSIX_VERSION)
  97. #define pid_t int
  98. typedef union wait WAIT;
  99. #else
  100. typedef int WAIT;
  101. #endif /* _POSIX_VERSION */
  102.  
  103. /* How to get the status of a job.  For Posix, this is just an int, but for
  104.    other systems we have to crack the union wait. */
  105. #if defined (_POSIX_VERSION)
  106. #define WSTATUS(t)  (t)
  107. #else
  108. #define WSTATUS(t)  (t.w_status)
  109. #endif
  110.  
  111. /* Make sure that parameters to wait3 are defined. */
  112. #ifndef WNOHANG
  113. #define WNOHANG 1
  114. #define WUNTRACED 2
  115. #endif
  116.  
  117. /* More Posix P1003.1 definitions.  In these definitions, `s' is a
  118.    `union wait' (the 1003.1 spec says they are `int'). */
  119. #if !defined (WSTOPSIG)
  120. #define WSTOPSIG(s)    ((s).w_stopsig)
  121. #define WTERMSIG(s)    ((s).w_termsig)
  122. #define WEXITSTATUS(s)    ((s).w_retcode)
  123. #endif /* WSTOPSIG */
  124.  
  125. #if !defined (WIFCORED)
  126. #if !defined (_POSIX_VERSION)
  127. #define WIFCORED(s)    ((s).w_coredump)
  128. #else
  129. #define WIFCORED(s)    ((s) & 0200)
  130. #endif /* _POSIX_VERSION */
  131. #endif /* WIFCORED */
  132.  
  133. /* I looked it up.  For pretty_print_job ().  The real answer is 24. */
  134. #define LONGEST_SIGNAL_DESC 24
  135.  
  136. /* We keep an array of jobs.  Each entry in the array is a linked list
  137.    of processes that are piped together.  The first process encountered is
  138.    the group leader. */
  139.  
  140. /* Each child of the shell is remembered in a STRUCT PROCESS.  A chain of
  141.    such structures is a pipeline.  The chain is circular. */
  142. typedef struct process {
  143.   struct process *next;    /* Next process in the pipeline.  A circular chain. */
  144.   pid_t pid;        /* Process ID. */
  145.   WAIT status;        /* The status of this command as returned by wait. */
  146.   int running;        /* Non-zero if this process is running. */
  147.   char *command;    /* The particular program that is running. */
  148. } PROCESS;
  149.  
  150. /* A description of a pipeline's state. */
  151. typedef enum { JRUNNING, JSTOPPED, JDEAD, JMIXED } JOB_STATE;
  152. #define JOBSTATE(job) (jobs[(job)]->state)
  153.  
  154. typedef struct job {
  155.   char *wd;        /* The working directory at time of invocation. */
  156.   PROCESS *pipe;    /* The pipeline of processes that make up this job. */
  157.   pid_t pgrp;        /* The process ID of the process group (necessary). */
  158.   int foreground;    /* Non-zero if this is running in the foreground. */
  159.   int notified;        /* Non-zero if already notified about job state. */
  160.   JOB_STATE state;    /* The state that this job is in. */
  161.   int job_control;    /* Non-zero if this job started under job control. */
  162. #ifdef JOB_CONTROL
  163.   COMMAND *deferred;    /* Commands that will execute when this job is done. */
  164. #endif
  165. } JOB;
  166.  
  167. #define NO_JOB -1    /* An impossible job array index. */
  168. #define DUP_JOB -2    /* A possible return value for get_job_spec (). */
  169.  
  170. #if !defined (_POSIX_VERSION) && !defined (sigmask)
  171. #define sigmask(x) (1 << ((x)-1))
  172. #endif /* !POSIX && !sigmask */
  173.  
  174. #ifndef SIGABRT
  175. #define SIGABRT SIGIOT
  176. #endif
  177.  
  178. #ifndef SIGCHLD
  179. #define SIGCHLD SIGCLD
  180. #endif
  181.  
  182. #if !defined (_POSIX_VERSION)
  183. #if !defined (SIG_BLOCK)
  184. #define SIG_BLOCK 2
  185. #define SIG_SETMASK 3
  186. #endif /* SIG_BLOCK */
  187.  
  188. /* Type of a signal set. */
  189. #define sigset_t int
  190.  
  191. /* Make sure there is nothing inside the signal set. */
  192. #define sigemptyset(set) (*(set) = 0)
  193.  
  194. /* Add SIG to the contents of SET. */
  195. #define sigaddset(set, sig) *(set) |= sigmask (sig)
  196.  
  197. /* Suspend the process until the reception of one of the signals
  198.    not present in SET. */
  199. #define sigsuspend(set) sigpause (*(set))
  200.  
  201. /* END of POSIX 1003.1 definitions. */
  202. #endif /* _POSIX_VERSION */
  203.  
  204. /* These definitions are used both in POSIX and non-POSIX implementations. */
  205.  
  206. #define BLOCK_SIGNAL(sig, nvar, ovar) \
  207.   sigemptyset (&nvar); \
  208.   sigaddset (&nvar, sig); \
  209.   sigemptyset (&ovar); \
  210.   sigprocmask (SIG_BLOCK, &nvar, &ovar)
  211.  
  212. #if defined (_POSIX_VERSION)
  213. #define BLOCK_CHILD(nvar, ovar) BLOCK_SIGNAL (SIGCHLD, nvar, ovar)
  214. #define UNBLOCK_CHILD(ovar) sigprocmask (SIG_SETMASK, &ovar, (sigset_t *) NULL)
  215. #else /* !_POSIX_VERSION */
  216. #define BLOCK_CHILD(nvar, ovar) ovar = sigblock (sigmask (SIGCHLD))
  217. #define UNBLOCK_CHILD(ovar) sigsetmask (ovar)
  218. #endif /* !_POSIX_VERSION */
  219.  
  220. /* System calls. */
  221. extern pid_t fork (), getpid (), getpgrp ();
  222.  
  223. /* Stuff from the jobs.c file. */
  224. extern pid_t  original_pgrp, shell_pgrp, pipeline_pgrp;
  225. extern pid_t last_made_pid, last_asynchronous_pid, make_child ();
  226. extern int current_job, previous_job;
  227. extern int asynchronous_notification;
  228. extern JOB **jobs;
  229. extern int job_slots;
  230.